package com.cskaoyan.config;

import com.cskaoyan.service.UserService;
import org.springframework.aop.framework.ProxyFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * @author stone
 * @date 2022/08/29 16:21
 */
@Configuration
@ComponentScan("com.cskaoyan")
public class SpringConfiguration {

    // jdk动态代理和cglib动态代理的代理类和委托类之间的关系
    // jdk动态代理：哥两，实现了相同的接口
    // cglib动态代理：父子，代理类继承了委托类
    @Bean
    public ProxyFactoryBean userServiceProxy(UserService userService) {
        ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
        //需要一些参数
        proxyFactoryBean.setTarget(userService); // 目标类（委托类组件）

        proxyFactoryBean.setInterceptorNames("countTimeAdvice"); // 通知组件的id

        return proxyFactoryBean;
    }
}
